/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoadingBarFrame.java
 *
 * Created on Mar 2, 2010, 9:07:35 PM
 */

package pacchess.base.gui;

import java.awt.Image;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import javax.swing.SwingWorker;
import pacchess.base.gui.thread.ImageResizer;
import pacchess.piece.allegiance.Allegiance;
import pacchess.piece.Piece;

/**
 *
 * @author hrothgar
 */
public class LoadingBarFrame
	extends javax.swing.JFrame
	implements PropertyChangeListener
{

    private SwingWorker worker;

    /** Creates new form LoadingBarFrame */
    public LoadingBarFrame(SwingWorker worker) {
        this(worker,100);
    }
    public LoadingBarFrame(SwingWorker worker, int max)
    {
	super();
	initComponents();
	setVisible(true);
	this.worker=worker;
	this.worker.addPropertyChangeListener(this);
    }

    public void execute()
    {
	worker.execute();
    }

     /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        progressBar = new javax.swing.JProgressBar();
        label = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setResizable(false);

        label.setFont(new java.awt.Font("DejaVu Sans", 0, 18));
        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setText("Loading PacChess...");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               // new LoadingBarFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel label;
    private javax.swing.JProgressBar progressBar;
    // End of variables declaration//GEN-END:variables

    public boolean isDone()
    {
	return worker.isDone();
    }

    public void propertyChange(PropertyChangeEvent pce) {
	if("progress" == pce.getPropertyName())
	{
	    int progress = (Integer) pce.getNewValue();
	    progressBar.setValue(progress);
	}
    }

}